package com.tanhua.server.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanhua.common.mapper.DayMapper;
import com.tanhua.common.mapper.RetentionldMapper;
import com.tanhua.common.pojo.AnalysisByDay;
import com.tanhua.common.pojo.Day;
import com.tanhua.common.pojo.Retentionld;
import com.tanhua.server.vo.AnalysisByDayVo;
import com.tanhua.server.vo.PageResult;
import com.tanhua.server.vo.RetentionldVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * @刘波
 * @2021/9/14 15:28
 */
@Service
public class RetentionldService {
    @Autowired
    private DayMapper dayMapper;

    @Autowired
    private RetentionldMapper retentionldMapper;

    public PageResult queryCheck(Long startTime, Long endTime, String gender, Integer page, Integer pageSize) {
        long dayTime = 24 * 60 * 60 * 1000;
        int numdayTime = (int) ((endTime - startTime) / dayTime);
        List<RetentionldVo> list = new ArrayList<>();
        for (int i = 0; i <=numdayTime; i++) {
            String format = new SimpleDateFormat("yyyy-MM-dd").format(startTime + (dayTime * i));
            LambdaQueryWrapper<Retentionld> lambdaQueryWrapper1 = new LambdaQueryWrapper<>();
            lambdaQueryWrapper1.eq(Retentionld::getDate, format);
           Retentionld rs = this.retentionldMapper.selectOne(lambdaQueryWrapper1);
            RetentionldVo retentionldVo = new RetentionldVo();
            retentionldVo.setDate(rs.getDate());
            retentionldVo.setRegistered(rs.getRegistered());
            retentionldVo.setAfterOne(rs.getAfterOne());
            retentionldVo.setAfterTwo(rs.getAfterTwo());
            retentionldVo.setAfterThree(rs.getAfterThree());
            retentionldVo.setAfterFoul(rs.getAfterFoul());
            retentionldVo.setAfterFive(rs.getAfterFive());
            retentionldVo.setAfterSix(rs.getAfterSix());
            retentionldVo.setAfterSeven(rs.getAfterSeven());
            retentionldVo.setAfterMonth(rs.getAfterMonth());
            list.add(retentionldVo);
        }
        PageResult pageResult = new PageResult(numdayTime, pageSize, numdayTime / pageSize, page, list);
        pageResult.setPage(page);
        pageResult.setPagesize(pageSize);
        pageResult.setItems(list);
        return pageResult;
    }

    public List<RetentionldVo> queryCheck(Long startTime, Long endTime){
        long dayTime = 24 * 60 * 60 * 1000;
        int numdayTime = (int) ((endTime - startTime) / dayTime);
        List<RetentionldVo> list = new ArrayList<>();
        for (int i = 0; i <=numdayTime; i++) {
            String format = new SimpleDateFormat("yyyy-MM-dd").format(startTime + (dayTime * i));
            LambdaQueryWrapper<Retentionld> lambdaQueryWrapper1 = new LambdaQueryWrapper<>();
            lambdaQueryWrapper1.eq(Retentionld::getDate, format);
            Retentionld rs = this.retentionldMapper.selectOne(lambdaQueryWrapper1);
            RetentionldVo retentionldVo = new RetentionldVo();
            retentionldVo.setDate(rs.getDate());
            retentionldVo.setRegistered(rs.getRegistered());
            retentionldVo.setAfterOne(rs.getAfterOne());
            retentionldVo.setAfterTwo(rs.getAfterTwo());
            retentionldVo.setAfterThree(rs.getAfterThree());
            retentionldVo.setAfterFoul(rs.getAfterFoul());
            retentionldVo.setAfterFive(rs.getAfterFive());
            retentionldVo.setAfterSix(rs.getAfterSix());
            retentionldVo.setAfterSeven(rs.getAfterSeven());
            retentionldVo.setAfterMonth(rs.getAfterMonth());
            list.add(retentionldVo);
        }
        return list;
    }
}
